package services;

import domain.entities.EquipmentType;
import domain.entities.Equipmentcertification;
import domain.entities.EquipmentcertificationDAO;
import domain.entities.Vendorcentral;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Guillermo
 * Date: 30/10/12
 * Time: 12:28
 * To change this template use File | Settings | File Templates.
 */
@Service
public class EquipmentcertificationService implements CRUDService<Equipmentcertification>{

    private EquipmentcertificationDAO equipmentcertificationDAO;

    public EquipmentcertificationService() {
    }

    @Autowired
    public EquipmentcertificationService(EquipmentcertificationDAO equipmentcertificationDAO) {
        this.equipmentcertificationDAO = equipmentcertificationDAO;
    }


    public List<Equipmentcertification> findAll(){
        return equipmentcertificationDAO.findAll();
    }

    public List<Equipmentcertification> findByCentroId(Integer centroId){
        return equipmentcertificationDAO.findByCentroId(centroId);
    }

    public Equipmentcertification findbyId(Integer id){
        return equipmentcertificationDAO.findById(id);
    }

    public void save(Equipmentcertification equipmentcertification){
        equipmentcertificationDAO.attachDirty(equipmentcertification);
    }

    public void deleteByCentroId(Integer centroId){
        equipmentcertificationDAO.deleteByCentroId(centroId);
    }

    @Override
    public <V extends Criteria> List<Equipmentcertification> list(V criteria) {
        List<Equipmentcertification> list = equipmentcertificationDAO.findAll();
        Iterator<Equipmentcertification> it = list.iterator();
        while(it.hasNext()){
            if(!criteria.isIn(it.next())){
                it.remove();
            }
        }
        return list;
    }
}
